package com.midian.model.activity;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.midian.common.system.SysStatic;
import com.midian.common.utils.StringUtil;
import com.midian.model.common.BaseModel;
import com.midian.model.organization.Organization;
import com.midian.model.user.User;
import com.midian.service.user.IUserService;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.Point;

/**
 * 活动用户（报名）
 * 
 */
@Entity
@Table(name = "activity_user")
public class ActivityUser extends BaseModel {
	/**订单号*/
	private String orderSn;
	/**活动id*/
	private String activityId;
	/**封面图片id*/
	private String coverPicId;
	/**活动标题*/
	private String title;
	/**活动开始时间*/
	private Date beginTime;
	/**参加活动的用户id*/
	private String joinUserId;
	/**大人数量*/
	private Integer adultCount;
	/**小孩数量*/
	private Integer childCount;
	/**大人价格*/
	private Double adultPrice;
	/**小孩价格*/
	private Double childPrice;
	/**联系人姓名*/
	private String contactPerson;
	/**联系人号码*/
	private String contactNum;
	/**报名状态：1，报名成功（已付款）；2，未付款*/
	private Integer joinState;
	/**支付方式：weixin，微信支付；alipay，支付宝支付*/
	private String payWay;
	@ManyToOne(optional=true,fetch=FetchType.LAZY)
	@JoinColumn(name="joinUserId",insertable=false, updatable=false)
	@NotFound(action=NotFoundAction.IGNORE)
	private User user;
	@ManyToOne(optional=true,fetch=FetchType.LAZY)
	@JoinColumn(name="activityId",insertable=false, updatable=false)
	@NotFound(action=NotFoundAction.IGNORE)
	private Activity activity;
	
	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getOrderSn() {
		return orderSn;
	}

	public void setOrderSn(String orderSn) {
		this.orderSn = orderSn;
	}

	public String getActivityId() {
		return activityId;
	}

	public void setActivityId(String activityId) {
		this.activityId = activityId;
	}

	public String getCoverPicId() {
		return coverPicId;
	}

	public void setCoverPicId(String coverPicId) {
		this.coverPicId = coverPicId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(Date beginTime) {
		this.beginTime = beginTime;
	}

	public String getJoinUserId() {
		return joinUserId;
	}

	public void setJoinUserId(String joinUserId) {
		this.joinUserId = joinUserId;
	}

	public Integer getAdultCount() {
		return adultCount;
	}

	public void setAdultCount(Integer adultCount) {
		this.adultCount = adultCount;
	}

	public Integer getChildCount() {
		return childCount;
	}

	public void setChildCount(Integer childCount) {
		this.childCount = childCount;
	}

	public Double getAdultPrice() {
		return adultPrice;
	}

	public void setAdultPrice(Double adultPrice) {
		this.adultPrice = adultPrice;
	}

	public Double getChildPrice() {
		return childPrice;
	}

	public void setChildPrice(Double childPrice) {
		this.childPrice = childPrice;
	}

	public String getContactPerson() {
		return contactPerson;
	}

	public void setContactPerson(String contactPerson) {
		this.contactPerson = contactPerson;
	}

	public String getContactNum() {
		return contactNum;
	}

	public void setContactNum(String contactNum) {
		this.contactNum = contactNum;
	}

	public Integer getJoinState() {
		return joinState;
	}

	public void setJoinState(Integer joinState) {
		this.joinState = joinState;
	}

	public String getPayWay() {
		return payWay;
	}

	public void setPayWay(String payWay) {
		this.payWay = payWay;
	}
	
	/**用户是否报名成功*/
	public String getIsJoinDesc() {
		String isJoinDesc = "";
		if(SysStatic.ACTIVITY_USER_IS_JOIN.equals(this.joinState)) {
			isJoinDesc = "报名成功（已付款）";
		} else {
			isJoinDesc = "未付款";
		}
		return isJoinDesc;
	}
	/**活动报名活动详情预览*/
	public String getActivityDetailTips(){
		String activityDetailTips = "";
		if (this.activity!=null) {
			if (StringUtils.isNotBlank(this.activity.getDetail())) {
				activityDetailTips = StringUtil.replaceToHtmlQuot(this.activity.getDetail());
			}
		}
		return activityDetailTips;
	}
	
	/**
	 * 帐号描述信息
	 * 
	 * @return
	 */
	@Transient
	public String getAccountDesc() {
		String accountDesc = "";
		if (this.user != null) {

			if (IUserService.USER_FROM_NORMAL.equals(user.getUserfrom()) && StringUtils.isNotBlank(user.getAccount())) {
				accountDesc = user.getAccount();
			} else if (IUserService.USER_FROM_QQ.equals(user.getUserfrom())) {
				accountDesc = "QQ用户";
			} else if (IUserService.USER_FROM_WECHAT.equals(user.getUserfrom())) {
				accountDesc = "微信用户";
			}
		}
		return accountDesc;
	}
	
	
}
